/*
*类描述：notice管理类
*开发者：sjc
*创建时间：2018-8-19 14:42:36
*/

//记录内容块
var ntId;
$(function () {
    //jumpPage(menu);
    //pubOptBtn.getOptBtn('introduce',menu,'2');
    //初始化富文本编辑框
    tinymce.init({convert_urls: false,
        selector: '.tinymce',
        height: 300,
        plugins: [
            'advlist autolink lists link image charmap print preview anchor',
            'searchreplace visualblocks code fullscreen',
            'insertdatetime media table contextmenu paste code'
        ],
        toolbar: 'insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
        init_instance_callback:getCon
    });

    if('0'==type){
        set0();
    }else{
        set1(type);
    }

    if(notice != null && notice != "undefined"){
        $("#noticeTitle").val(notice.title);
        $("#noticeId").val(notice.id);
        $("#noticeType").val(notice.noticeType);
        ntId = notice.id;
        var memberList=new Array();
        memberList=notice.sendIdList;
        sessionStorage.setItem("memberList",JSON.stringify(memberList));
        $("input[type='radio'][name='acceptObj']").eq(0).attr("checked",true);
        if(memberList.length>0 && memberList[0] != "0"){
            $("input[type='radio'][name='acceptObj']").eq(1).attr("checked",true);
        }
        //给富文本编辑器赋值
        //
        // $(".tinymce").val(notice.content);
        var temp = [];
        //循环读取图片
        if (naList != null && naList != "undefined") {
            $.each(naList, function (i, obj) {
                temp.push(obj.attachmentUrl);
            });
            //初始化图片展示
            $("#case").attr("data-value", temp);
        }
    }

    $("#case").upload(
        function (_this, data) {
            layer.msg("图片链接："+data,{time: 5000},function(){
            });
        }
    )


    $("input[name=acceptObj]").click(function(){
        ntId = $("#noticeId").val();
        if(ntId == null || ntId == "" || ntId == "undefined"){
            layer.msg('请保存标题',{icon:3})
            return false;
        }
        var accept = $(this).val();
        if(accept == "2"){
            $.ajax({
                url:application.contextPath+"/notice/showMemberPage?noticeId="+ntId,
                success:function(res){
                    layer.open({
                        type:1,
                        title:'选择需要发送的人员',
                        content:res,
                        maxmin:true,//最大，最小开关
                        shade:0.5,//遮盖层模糊度
                        anim:1,//打开跟关闭动画
                        scrollbar:true,//是否设置滚轮
                        area:["1080px","510px"]
                    })
                }
            })
        }
    });


});

function getCon() {
    tinyMCE.activeEditor.setContent(notice.content);
}

function set0(){

}
function set1(aaa){

}
/**
 * 方法描述:保存编辑块内容
 * SJC 2018-8-27 15:29:58
 *
 */
function updateNoticeDetail(item){
    var ntId = $("#noticeId").val();
    var noticeTitle = $("#noticeTitle").val();
    var noticeType = $('#noticeType option:selected') .val();
    var contentDetail = tinymce.activeEditor.getContent();
    var despatcher=$("input[name='acceptObj']:checked").val();
    var memberList=new Array();
    var member="0";
    if("2" == despatcher){
        memberList= JSON.parse(sessionStorage.getItem("memberList"));
    }else{
        memberList.push(member);
    }
    $.ajax({
        url:application.contextPath+"/notice/updateNoticeTiny",
        type:"POST",
        contentType: "application/json; charset=utf-8",
        dataType:"json",
        data:JSON.stringify({
            "noticeId":ntId,
            "title":noticeTitle,
            "type":"2",
            "contentDetail":contentDetail,
            "authorId":notice.authorId,
            "memberList":memberList
        }),
        success:function (res) {
            if(res.isSuccess){
                layer.msg('修改内容成功', {
                    icon: 1, title: '修改提示', btn: ['是'], yes() {
                        layer.close(layer.index);
                        loadUtil = new Load($);
                        loadUtil.load({
                            container: '#homeContent',
                            url: application.contextPath + "/index/toUpdateTeachSystemTiny"
                        });
                    }
                });
            }else {
                layer.open({
                    title:"加载失败!",
                    content:'页面加载失败!'
                });
            }
        }
    });
}
